package com.lwx.chapter4;

import java.util.Arrays;

public class heapSort1 {
    public static void main(String[] args) {
        heapSort1 h = new heapSort1();
        Integer[] arr = {1,5,3,4,2};
        h.heapSort(arr,5);
        System.out.println(Arrays.toString(arr));
        Integer[] arr1 = {1,5,3,4,2};
        MaxHeap maxHeap = new MaxHeap(arr1,5);
        System.out.println(Arrays.toString(arr1));
    }
    public void heapSort(Integer[] arr, int n) {
        MaxHeap maxHeap = new MaxHeap(n);
        for (int i = 0; i < n; i++) {
            maxHeap.insert(arr[i]);
        }
        for (int i = 0; i < arr.length; i++) {
            arr[i] = maxHeap.extractMax();
        }
    }

}
